import requests,time
from bs4 import BeautifulSoup

def login(username, password):
    Cookie =  "uuid_tt_dd=-1110282737856396080_20171103; LSSC=LSSC-2585211-4xfz4sLeZ4iQdie1WhlThTABjbMPoR-passport.csdn.net; BT=1510039919521; __message_sys_msg_id=0; __message_gu_msg_id=0; __message_cnel_msg_id=0; __message_in_school=0; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1510647312,1510647679,1510648530,1510652703; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1510652703; dc_tos=ozej32; dc_session_id=1510652702991_0.6184707834885541"
    Accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
    Connection = 'keep-alive';
    Host = 'www.csdn.net'
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0','Cookie': Cookie,'Accept':Accept,
               'Connection':Connection, 'Host':Host,'Referer':'https://www.csdn.net/'}
    JSESSIONID = "BBD872BE95234D7F00EF390581D6B33A.tomcat2"
    sessions = requests.session();
    xyz = sessions.get('https://passport.csdn.net/account/login?from=http://my.csdn.net/my/mycsdn', headers=headers).content;
    # _xsrf = BeautifulSoup(sessions.get('https://passport.csdn.net/account/login?from=http://my.csdn.net/my/mycsdn',headers=headers).content,'html.parser').find('input',attrs={'name':'_xsrf'}).get('value')

    data = {
        "username": username,
        "password": password,
        "lt": "LT-343222-0amRQyMwWdw0kC0LGX0kAXmGcY0Wie",
        "execution	e1s": "1",
        "_eventId":"submit"
    }
    res = sessions.post("https://passport.csdn.net/account/login;jsessionid=BBD872BE95234D7F00EF390581D6B33A.tomcat2?from=http://my.csdn.net/my/mycsdn",data,headers=headers).content
    print res;

if __name__ == "__main__":
   login("oplqw12345","123321");